import Vue from 'vue'
import Vuex from 'vuex'
import axios from "axios";

Vue.use(Vuex)

//导入持久化插件
import creteState from 'vuex-persistedstate'

export default new Vuex.Store({
  //使用插件
  plugins: [creteState()],

  state: {
    token:"",
    user:{}
  },
  
  mutations: {
    //更新token
    updateToken(state,val) {
      state.token=val
    },
    //更新UserInfo
    updateUserInfo(state,val){
      state.user=val
    }
  },
  actions: {
    //异步更新用户信息
   async getUserInfo(context){
      const {data:res} = await axios.get('/my/userinfo')
         console.log(res);
         context.commit('updateUserInfo',res.data)
    },
    
  }

})
